(function(){

'use strict';

angular.module('controllers.faultLocation.pbossOm')
  .controller('networkController', newWorkResourceController);

function newWorkResourceController(resourceServer) {
  var diskEcharts1 = echarts.init(document.getElementById('cpu1'));
  var diskEcharts2 = echarts.init(document.getElementById('cpu2'));
  var diskEcharts3 = echarts.init(document.getElementById('cpu3'));
  networks();
  function networks() {
    resourceServer.networks(function(res) {
      var arr1 = res.data[0];
      var arr2 = res.data[1];
      var arr3 = res.data[2];
      diskEcharts1.setOption(Echarts(arr1.hostip));
      diskEcharts2.setOption(Echarts(arr2.hostip));
      diskEcharts3.setOption(Echarts(arr3.hostip));
      setInterval(function() {
        diskEcharts1.addData([
          [0, Math.round(Math.random() * 100), false, false]
        ]);
        diskEcharts2.addData([
          [0, Math.round(Math.random() * 100), false, false]
        ]);
        diskEcharts3.addData([
          [0, Math.round(Math.random() * 100), false, false]
        ]);
      }, 2000);
    })
  }



  function Echarts(textName) {
    var option = {};
    option.title = {
      text: textName
    };
    option.tooltip = {
      trigger: 'axis'
    };
    option.calculable = true;
    option.xAxis = [{
      type: 'category',
      boundaryGap: true,
      data: (function() {
        var res = [];
        var len = 60;
        while (len--) {
          res.push('');
        }
        return res;
      })()
    }];
    option.yAxis = [{
      type: 'value',
      name: 'k/S',
      scale: true,
      boundaryGap: [0.2, 0.2]
    }];
    option.series = [{
      type: 'line',
      data: (function() {
        var res = [];
        var len = 60;
        while (len--) {
          res.push(0);
        }
        return res;
      })(),
        smooth:true,
       itemStyle: {normal: {areaStyle: {type: 'default'}}}
    }];
    return option;
  }
}
newWorkResourceController.$inject = ['resourceServer'];

})();